<?php

	function getsitetitle($siteurl){
		$math = preg_match("/^https?:\/\/(www)?\.?([^\.]{1,}?)\.(.*?)$/ism",$siteurl,$match);
		return (" - ".ucfirst($match[2]));
	}
	$enableSitetitle = true;
	$content = $_POST['data'];
	$title = $_POST['title'];
	$site_arr = array(
		"http://www.fileserve.com",
		"http://hotfile.com",
		"http://www.filesonic.com"
	);
	$pos = strpos($content, "[/");
	if($pos !== false){
		$math = preg_match("/\](.*?)\[\//ism",$content,$match);
		$math1 = preg_match_all("/^\s*?http(.*?)$/ism",$match[1],$match1);
	}else{
		$math1 = preg_match_all("/^\s*?http(.*?)$/ism",$content,$match1);
	}
	$mymatch = $match1[0];
	// foreach($match1[0] as $key=>$value){
		// $myval = trim($value);
		// if(strlen($title)>0){
			// $partnum = $key+1;
			// $sitetitle = ($enableSitetitle == true ? getsitetitle($myval) : "");
			// echo $match1[0][$key] = "[url=".$myval."]{$title}{$sitetitle} - Part {$partnum}[/url]";
		// }else{
			// echo $match1[0][$key] = "[url=".$myval."]{$myval}[/url]";
		// }
		// echo "\n";
	// }
	
	foreach($mymatch as $key=>$value){
		$myval = trim($value);
		if(strlen($title)>0){
			$partnum = $key+1;
			$sitetitle = ($enableSitetitle == true ? getsitetitle($myval) : "");
			echo $match1[0][$key] = "<a href=\"".$myval."\">{$title}{$sitetitle} - Part {$partnum}</a>";
		}else{
			echo $match1[0][$key] = "<a href=\"".$myval."\">{$myval}</a>";
		}
		echo "\n";
	}
	// echo "<pre>";
	// print_r($match1);
	// echo "</pre>";
	
	
	
?>